// Created by lostleaf on 2020/5/23.
// vn.py 宽睿 OES 箭鱼快速订单系统 python 封装类型定义

#pragma once

#include <oes_api/oes_async_api.h>
#include <sutil/logger/spk_log.h>

#include "oes_utils.h"

class TdApi {
private:
  OesAsyncApiContextT *p_context = nullptr;  //API Context对象
  OesAsyncApiChannelT *p_ord_channel = nullptr; //委托通道
  OesAsyncApiChannelT *p_rpt_channel = nullptr; //回报通道
  OesApiSessionInfoT *p_qry_channel = nullptr; //查询通道
  OesApiClientCfgT api_cfg{NULLOBJ_OESAPI_CLIENT_CFG};

  std::thread task_thread; //工作线程指针（向python中推送数据）
  TaskQueue<TdTask> task_queue; //任务队列
  bool active = false; //工作状态

public:
  TdApi() = default;
  ~TdApi() = default;

  /** 对接收到的回报消息进行处理的回调函数 */
  friend int32 vnTdMsgHandler(OesApiSessionInfoT *pSessionInfo,
                              SMsgHeadT *pMsgHead,
                              void *pMsgBody,
                              void *pCallbackParams);
  void processTask();

  bool init(const std::string &config_path);
  void stop();

  int32 sendBatchOrdersReq(const py::list& reqs);

  //自动生成的函数定义
#include "vnoestd_function_header.h"
};